package com.itheima.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration  //代表着是一个配置类
@EnableSwagger2  //开启丝网哥
@EnableKnife4j   //开启knife4j
public class SwaggerConfig {

  @Bean
  public Docket createRestApi() {
    // 文档类型
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        //basePackage 路径必须扫描到所有的controller  (需要修改地方)
        .apis(RequestHandlerSelectors.basePackage("com.itheima"))
        .paths(PathSelectors.any())
        .build();
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        //文档标题
        .title("汇客商业")
        //文档版本
        .version("1.0")
        //文档描述
        .description("汇客商业接口文档")
        .build();
  }

}